package com.emm.yixun.mobile.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.emm.yixun.mobile.R;
import com.emm.yixun.mobile.model.GetHouseTypeList.HouseTypeList;

public class AttenAdapter extends BaseAdapter {

	Context context;

	ArrayList<HouseTypeList> name;

	public AttenAdapter(Context context, ArrayList<HouseTypeList> name) {
		this.context = context;
		this.name = name;
	}

	public void GetDate(ArrayList<HouseTypeList> name) {
		this.name = name;
		notifyDataSetChanged();
	}

	@Override
	public int getCount() {
		return name == null ? 0 : name.size();
	}

	@Override
	public Object getItem(int position) {
		return name == null ? null : name.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		ViewHd v = null;
		if (convertView == null) {
			convertView = LayoutInflater.from(context).inflate(R.layout.attst_item, null);
			v = new ViewHd();
			v.spinner_name = (TextView) convertView.findViewById(R.id.spinner_name);
			v.select_image_att = (ImageView) convertView.findViewById(R.id.select_image_att);
			convertView.setTag(v);
		} else {
			v = (ViewHd) convertView.getTag();
		}
		v.spinner_name.setText(name.get(position).getHouseTypeName());

		if (name.get(position).isIsselecet()) {
			v.select_image_att.setBackgroundResource(R.drawable.ico_selt);
		} else {
			v.select_image_att.setBackgroundResource(R.drawable.ico_delt_no);
		}
		v.select_image_att.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				Log.w("p", "" + position);
				if (name.get(position).isIsselecet()) {
					name.get(position).setIsselecet(false);
				} else {
					name.get(position).setIsselecet(true);
				}
				notifyDataSetChanged();
			}
		});
		return convertView;
	}

	public static class ViewHd {
		TextView spinner_name;

		ImageView select_image_att;
	}

}
